/**
 * Created by zhanglihe on 16/1/15.
 */
require.config(require_config);

define([
    'jquery',
    'common',
    'ready',
    'collection',
    'datepicker'
], function ($, common, ready, Collection, datepicker) {

    var index = function () {
        this.init();
    };
    index.prototype = {
        init: function () {
            loading();
            this.fetch();
            this.event();
        },

        fetch: function () {
            var _this = this;
            this.collection = new Collection({
                url: _global.url.api + 'embed_order/0',
                condition: {'status': 'count'},
                callback: function () {
                    loaded();//移除加载效果
                }
            });
            this.collection.fetch();
        },

        event: function () {
            var _this = this;
            //日期
            $('.long_date').on('click', function () {
                WdatePicker({
                    el: this.id,
                    dateFmt: 'yyyy-MM-dd HH:mm'
                });
            });
            /**
             * 搜索事件
             */
            $('#btn-search').on('click', function (e) {
                e.preventDefault();
                _this.collection.condition.keyword = $('input[name="keyword"]').val();
                _this.collection.condition.start_time = $('input[name="start_time"]').val();
                _this.collection.condition.end_time = $('input[name="end_time"]').val();
                _this.collection.condition.time_type = 1;
                _this.collection.reload();
            });
            $('#btn-time').find('a').on('click', function (e) {
                e.preventDefault();
                _this.collection.condition.date = $(this).attr('rel');
                $(this).addClass('active').siblings().removeClass('active');
                $('input[name="keyword"]').val('');
                $('input[name="start_time"]').val('');
                $('input[name="end_time"]').val('');
                _this.collection.condition.keyword = $('input[name="keyword"]').val();
                _this.collection.condition.start_time = $('input[name="start_time"]').val();
                _this.collection.condition.end_time = $('input[name="end_time"]').val();
                _this.collection.condition.time_type = 1;
                _this.collection.reload();
            });
        }
    };
    new index();

});